<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>9.组件自定义事件（子->父）:v-on</title>
    <script src="js/vue.js"></script>
</head>

<body>

    <div id="app">
        total:{{total}}
        <button-counter v-on:increment="incrementTotal"></button-counter>
        <button-counter v-on:increment="incrementTotal"></button-counter>
    </div>
    <script>
        // 点击计数:模板-》方法
        var buttonCounter = {
            //参数
            data: function () {
                return {
                    counter: 0
                }
            },
            //方法
            methods: {
                incrementHandler: function () {
                    this.counter += 1
                    this.$emit('increment')
                }
            },
            //模板
            template: '<button v-on:click="incrementHandler">{{counter}}</button>'
        }


        new Vue({
            el: '#app',
            components: {
                'button-counter': buttonCounter
            },
            data: {
                total: 0
            },
            methods: {
                incrementTotal: function () {
                    this.total += 1
                }
            }
        })
    </script>
</body>

</html>